Imports Owner.Framework.Data
Imports Owner.Framework.Data.DataFunctions

Namespace Tafi.VisionColor.DataService

    Public Class Us_WebDS

        Public Function GetUserBySign(ByVal pContrato As String, ByVal pCuitDNI As String) As Entities.Us_Web
            Dim args As QueryArgs
            Dim oDT As Data.DataTable
            Dim oUser As Entities.Us_Web = Nothing

            Try

                args = New QueryArgs
                args.ProcedureName = "W_GetUserBySign"
                args.Parameters.Add("pNroContrato", pContrato)
                args.Parameters.Add("pNroDocCUIT", pCuitDNI)

                oDT = ExecuteDataTable(args)

                If Not oDT Is Nothing Then
                    If oDT.Rows.Count > 0 Then
                        oUser = New Entities.Us_Web

                        With oUser
                            .Contrato = pContrato
                            .Cuenta = DbNullToInt32(oDT.Rows(0), "CXA_Cuenta")
                            .Abonado = DbNullToInt32(oDT.Rows(0), "CON_ABONADO")
                            .Nombre = DbNullToString(oDT.Rows(0), "ABO_NOMBRE")
                            .TipoContrato = DbNullToInt32(oDT.Rows(0), "CON_TIPCON")
                            .Apellido = DbNullToString(oDT.Rows(0), "ABO_APELLIDO")
                            .DNI = DbNullToString(oDT.Rows(0), "ABO_DNI")
                            .Cuit = DbNullToString(oDT.Rows(0), "CON_CUIT")
                            .TipoIVA = DbNullToInt32(oDT.Rows(0), "CON_TIPCON")
                            .RazonSocial = DbNullToString(oDT.Rows(0), "CON_RAZONSOCIAL")
                            .CalleName = DbNullToString(oDT.Rows(0), "ABO_CALLENAME")
                            .CalleNro = DbNullToInt32(oDT.Rows(0), "ABO_CALLENRO")
                            .CalleDepto = DbNullToString(oDT.Rows(0), "ABO_CALLEDPTO")
                            .Localidad = DbNullToString(oDT.Rows(0), "DescriLocaliAbonado")
                            .Telefono = DbNullToString(oDT.Rows(0), "ABO_TELEFONO")
                            .Barrio = DbNullToString(oDT.Rows(0), "ABO_BARRIO")
                            .Sucursal = DbNullToString(oDT.Rows(0), "CON_SUCURSAL")
                            .UserId = DbNullToString(oDT.Rows(0), "CON_USERID")
                            .CodCuenta = DbNullToString(oDT.Rows(0), "CUE_CODIGO")

                        End With

                    End If
                End If

                Return oUser
            Finally
                oUser = Nothing
                args = Nothing
                oDT = Nothing
            End Try
        End Function


        Public Function GetSaldo(ByVal pContract As Integer, ByVal pCuenta As Integer) As Double
            Dim args As QueryArgs
            Dim oDT As Data.DataTable
            Dim cant As Int16
            Dim Saldo As Double
            Try
                args = New QueryArgs
                'args.ConnectionKey = Owner.Framework.Configuration.SettingsManager.GetValue("Hera")
                args.ProcedureName = "DocumentosCuentaCorriente"
                args.Parameters.Add("pContrato", pContract)
                args.Parameters.Add("pCuenta", pCuenta)
                args.Parameters.Add("pDesde", DBNull.Value)
                args.Parameters.Add("pHasta", DBNull.Value)
                args.Parameters.Add("pSinSaldo", 0)


                oDT = ExecuteDataTable(args)


                If Not oDT Is Nothing Then
                    If oDT.Rows.Count > 0 Then
                        cant = oDT.Rows.Count - 1
                        Saldo = Math.Abs(Convert.ToDouble(oDT.Rows(cant)("Saldo")))

                        Return Saldo
                    End If

                Else
                    Return 0
                End If

            Catch ex As Exception
                Throw ex
            Finally
                args = Nothing
                oDT = Nothing
            End Try
        End Function


        Public Function GetUserByFilter(ByVal pDocumento As String, ByVal pServicio As String) As Entities.Us_Web
            Dim args As QueryArgs
            Dim oDT As Data.DataTable
            Dim oUser As Entities.Us_Web = Nothing
            Try
                args = New QueryArgs

                args.QueryMethod = QueryArgs.QueryMethodType.QueryText
                args.Query = "Select Documento, Id, Nombre, Domicilio, Correo, Telefono, ContactId, Servicio, " & _
                              "EXARMARIO, EXPAR1, EXPAR2, EXPUERTO, EXTELEFONO, EXIdArmario, EXIdPar1, EXIdPar2, EXIdPuerto, EXIdTelefono " & _
                              "From Us_Web01 Where Servicio='" & pServicio & "' And Documento='" & pDocumento.Replace("'", "''") & "';"

                oDT = ExecuteDataTable(args)

                If Not oDT Is Nothing Then
                    If oDT.Rows.Count > 0 Then
                        oUser = New Entities.Us_Web

                        With oUser
                            '.Documento = DbNullToString(oDT.Rows(0), "Documento")
                            '.Id = DbNullToString(oDT.Rows(0), "Id")
                            '.Nombre = DbNullToString(oDT.Rows(0), "Nombre")
                            '.Domicilio = DbNullToString(oDT.Rows(0), "Domicilio")
                            '.Telefono = DbNullToString(oDT.Rows(0), "Telefono")
                            '.Correo = DbNullToString(oDT.Rows(0), "Correo")

                            '.EXIdArmario = DbNullToInt32(oDT.Rows(0), "EXIdArmario")
                            '.EXIdPar1 = DbNullToInt32(oDT.Rows(0), "EXIdPar1")
                            '.EXIdPar2 = DbNullToInt32(oDT.Rows(0), "EXIdPar2")
                            '.EXIdPuerto = DbNullToInt32(oDT.Rows(0), "EXIdPuerto")
                            '.EXIdTelefono = DbNullToInt32(oDT.Rows(0), "EXIdTelefono")

                            '.EXARMARIO = DbNullToString(oDT.Rows(0), "EXARMARIO")
                            '.EXPAR1 = DbNullToString(oDT.Rows(0), "EXPAR1")
                            '.EXPAR2 = DbNullToString(oDT.Rows(0), "EXPAR2")
                            '.EXPUERTO = DbNullToString(oDT.Rows(0), "EXPUERTO")
                            '.EXTELEFONO = DbNullToString(oDT.Rows(0), "EXTELEFONO")
                            '.Servicio = DbNullToString(oDT.Rows(0), "Servicio")
                            '.ContactId = DbNullToLong(oDT.Rows(0), "ContactId")
                        End With

                    End If
                End If

                Return oUser
            Finally
                oUser = Nothing
                args = Nothing
                oDT = Nothing
            End Try
        End Function

    End Class

End Namespace
